<template>
	<view class="historyPosition">
		<view class="position-title">
			<view :class="active==0?'ming':''" @click="activeH">慧慧</view>
			<view :class="active==1?'ming':''" @click="activeM">鸣鸣</view>
		</view>
		<view class="position" v-if="active==0">
			<view class="position_item" v-for="(item,index) in wshAddress" @click="toMap(item)">
				<view class="position_item_title">慧慧</view>
				<view class="position_item_content">
					<view>经度：{{item.longitude}}</view>
					<view>纬度：{{item.latitude}}</view>
					<view>详细地址：{{item.address}}</view>
					<view class="time">{{item.date}}</view>
				</view>
			</view>
		</view>
		<view class="position" v-if="active==1">
			<view class="position_item" v-for="(item,index) in wsmAddress" @click="toMap(item)">
				<view class="position_item_title">鸣鸣</view>
				<view class="position_item_content">
					<view>经度：{{item.longitude}}</view>
					<view>纬度：{{item.latitude}}</view>
					<view>详细地址：{{item.address}}</view>
					<view class="time">{{item.date}}</view>
				</view>
				<!-- {{address}} -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				active: 0,
				address:undefined,
				wshAddress:undefined,
				wsmAddress:undefined,
			}
		},
		onLoad() {
		this.getPostion()
		},
		//监听下拉刷新动作
		 onPullDownRefresh () {
		    console.log('触发下拉刷新了')
			this.getPostion()
		  },
		methods: {
			toMap(item){
				console.log(item.latitude)
				uni.openLocation({
					latitude:parseFloat(item.latitude) ,
					longitude:parseFloat(item.longitude),
					success: () => {
						console.log("success")
					},
					fail: (err) => {
						console.log(err)
					}
				})
			},
			//获取数据从后台
			getPostion(){
				uni.request({
					url:"http://www.wangshuaiming.xyz:8080/app/getadress",
					success: (res) => {
						this.wshAddress =res.data.filter(item=> item.flag==1).reverse()
						this.wsmAddress =res.data.filter(item=> item.flag==0).reverse()
						this.address=res.data.reverse()
						uni.stopPullDownRefresh()
					},
					fail: (err) => {
						console.log(err)
					}
				})
			},
			activeH() {
				this.active = 0
			},
			activeM() {
				this.active = 1
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F8F9FB;
	}

	.historyPosition {
		.position-title {
			width: 100%;
			height: 100rpx;
			background: #FFFFFF;
			display: flex;
			justify-content: space-between;
			border-bottom: 1px solid #eee;

			view {
				width: 50%;
				height: 100%;
				text-align: center;
				line-height: 100rpx;
				font-size: 40rpx;
			}

			.ming {
				background-color: $main;
			}
		}

		.position {
			width: 100%;
			.position_item {
				padding:0 20rpx;
				background-color: #FFFFFF;
				border-radius: 50rpx;
				box-sizing: border-box;
				height: 300rpx;
				margin-top: 25rpx;
				padding-top: 25rpx;
				position: relative;
				.position_item_title {
					font-size: 30rpx;
					font-weight: 700;
					margin-left: 20rpx;
				}

				.position_item_content {
					font-size: 30rpx;
					padding-left: 15rpx;
					line-height: 50rpx;
					.time{
						position: absolute;
						bottom: 10rpx;
						right: 30rpx;
						font-size: 24rpx;
						color: #C0C0C0;
					}
				}
			}
		}
	}
</style>
